import { jumpUrl } from '@/utils';
import { useGetToken } from '@/utils/request';
import { Button, type ButtonProps } from 'antd';
import React from 'react';
import { useModel } from 'umi';
const AuthButton: React.FC<ButtonProps> = (props) => {
  const { children, onClick, ...rest } = props;
  const { token } = useGetToken();
  const { user } = useModel('userModel');
  const { finishFillInfoDate } = user || {};
  return (
    <Button
      onClick={(e) => {
        if (token) {
          if (finishFillInfoDate) {
            if (onClick) {
              onClick(e);
            }
          } else {
            jumpUrl('/info');
          }
        } else {
          jumpUrl('/login');
        }
      }}
      {...rest}
    >
      {children}
    </Button>
  );
};

export default AuthButton;
